<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>后盾人</title>
  </head>
  <body></body>
  <script>
    let cart = [
      { name: "iphone", price: 12000 },
      { name: "imac", price: 25000 },
      { name: "ipad", price: 3600 }
    ];
    // function maxPrice(goods) {
    //   return cart.reduce(function(pre, cur) {
    //     return pre.price > cur.price ? pre : cur;
    //   });
    // }
    // console.log(maxPrice(cart));
    function sum(goods) {
      return goods.reduce(function(total, cur) {
        return (total += cur["price"]);
      }, 0);
    }
    console.log(sum(cart));
  </script>
</html>
